/**
 * 
 */
package com.feib.soeasy.service.impl;

import java.io.IOException;
import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;

import com.feib.soeasy.job.importor.ImportJob;
import com.feib.soeasy.model.UploadFile;
import com.feib.soeasy.model.User;
import com.feib.soeasy.service.AsyncService;
import com.feib.soeasy.util.SpringContextUtil;

/**
 * @title (#)SyncServiceImpl.java<br>
 * @description 配合中租自動上傳需求，將原本非同步檢核，改用同步檢核<br>
 * @author Jimmy Liu<br>
 * @version 1.0.0 2012/09/23
 * @copyright Far Eastern International Bank Copyright (c) 2010<br>
 * @2010/12/3 create by Jimmy Liu<br>
 */
@Service("syncServiceImpl")
public class SyncServiceImpl  extends BaseServiceImpl implements AsyncService 
{

	@Override
	public void doFileImport(Long uploadFilePk) {
		
		ImportJob importJob = (ImportJob)SpringContextUtil.getBean("importJob");
        
        Date start = new Date();
        logger.info("帳單整批匯入開始 -" + ImportJob.BASIC_DATE_TIME_FORMAT.format(start));
        try {
        	importJob.setFailMailforceToIt(true); // 檢核失敗，強制發送給IT
            importJob.execute(uploadFilePk);           
        }
        catch (Exception e) {
            ImportJob.logger.error(e.getMessage(), e);
            try {
                importJob.exceptionNotice(e, uploadFilePk);
            }
            catch (IOException e1) {
                ImportJob.logger.error("完全無法發送MAIL給IT", e);
            }
        }
        finally{
            Date end = new Date();
            logger.info("帳單整批匯入結束 -" + ImportJob.BASIC_DATE_TIME_FORMAT.format(end));
            logger.info("共費時  - " + ((end.getTime() - start.getTime()) / 1000) + " 秒 ");
        }
	}

	@Override
	public void doPayerFileImport(Long uploadFilePk) {
		throw new RuntimeException("尚未實做");
	}

	@Override
	public void doCreateReport(Long uploadFilePk, User modifyUser) {
		throw new RuntimeException("尚未實做");		
	}

	@Override
	public void doBatchCreateReport(List<UploadFile> uploadFiles,
			User modifyUser) {
		throw new RuntimeException("尚未實做");		
	}

}
